<?php


function getFileExtend($filestr) {
    $extend = explode(".", $filestr);
    $va = count($extend) - 1;
    return $extend[$va];
}

function generateNewFile($ext = "txt") {
    $result = '';
    $result .= microtime();
    $result .= rand(10000, 99999);
    $result = preg_replace('/[\. ]/', '', $result);
    return $result . "." . $ext;

}

function isExtendFile($fname, $extlist) {
    return in_array(getFileExtend($fname), $extlist);
}

function saveUploadFile($fieldname, $destpath) {
    $src_filename = $_FILES[$fieldname]["tmp_name"];
    $dest_filename = $destpath;
    return move_uploaded_file($src_filename, $dest_filename);
}

